package com.webull.information.center.carwler.common.util.jsoup;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;

import com.webull.framework.util.UtilJson;

public class SelectorDemo2 {
	public static void main(String[] args) throws IOException {
		final Pattern pattern1 = Pattern.compile("(WAS)(\\s){0,1}<(\\S{1,})>");
		final Pattern pattern2 = Pattern.compile("(NOW)(\\s){0,1}<(\\S{1,})>");
		List<String> strs = FileUtils.readLines(new File("C:/Users/Administrator/Documents/编辑1.txt"), "utf-8");

		for (String str : strs) {
			boolean has = false;
			Map<String, Object> aa = UtilJson.toMap(str);

			List<String> keys = new ArrayList<String>(aa.keySet());
			Collections.sort(keys);

			String[] suf = new String[2];
			for1_: for (int i = 0; keys != null && i < keys.size(); i++) {
				if (!StringUtils.startsWith(keys.get(i), "row")) continue for1_;
				String value = (String) aa.get(keys.get(i));
				if (suf[0] == null && suf[1] == null) {
					Matcher m = pattern1.matcher(value);
					if (m.find()) suf[0] = StringUtils.substringBetween(m.group(), "<", ">");
				} else if (suf[0] != null && suf[1] == null) {
					Matcher m = pattern2.matcher(value);
					if (m.find()) suf[1] = StringUtils.substringBetween(m.group(), "<", ">");
				}
				if (suf[0] != null && suf[1] != null && !StringUtils.equals(suf[0], suf[1])) {
					System.out.println(suf[0] + "\t" + suf[1]);
					// System.out.print("'" + suf[1] + "',");
					suf = new String[2];
					has = true;
				}

			}
			// if (has) System.out.println();
		}
	}

	public static void main2(String[] args) {
		Pattern pattern = Pattern.compile("(WAS|NOW)(\\s){1}<(\\S{1,})>");

		String a = "18Aug10 TEIXEIRA DUAR NV WAS <TDUn.LS> PTTD10AM0000 TDSA ORD";
		Matcher m = pattern.matcher(a);
		System.out.println(m.find() ? m.group() : "");
	}
}
